/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NATIVE_NET_CONN_API_H
#define NATIVE_NET_CONN_API_H

/**
 * @addtogroup NetConn
 * @{
 *
 * @brief Provides C APIs for the data network connection module of network management.
 *
 * @since 11
 * @version 1.0
 */

/**
 * @file native_net_conn_api.h
 *
 * @brief Provides C APIs for the data network connection module of network management.
 *
 * @syscap SystemCapability.Communication.NetManager.Core
 * @since 11
 * @version 1.0
 */

#include "native_net_conn_type.h"
#include "netdb.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Obtains the DNS result based on <b>netId</b>.
 *
 * @param host Host name.
 * @param serv Service name.
 * @param hint Pointer to the <b>addrinfo</b> structure.
 * @param res DNS query result, which is in the format of linked lists.
 * @param netId Network ID. If <b>netId</b> is <b>0</b>, the default network ID is used for DNS query.
 * @return 0: success.
 * @return 201: insufficient permission.
 * @return 401: parameter error.
 * @return 2100002: service connection failure.
 * @return 2100003: internal error.
 * @permission ohos.permission.INTERNET
 * @syscap SystemCapability.Communication.NetManager.Core
 * @since 11
 * @version 1.0
*/
int32_t OH_NetConn_GetAddrInfo(char *host, char *serv, struct addrinfo *hint, struct addrinfo **res, int32_t netId);

/**
 * @brief Releases the DNS query result.
 *
 * @param res DNS query result, which is in the format of linked lists.
 * @return 0: success.
 * @return 201: insufficient permission.
 * @return 401: parameter error.
 * @return 2100002: service connection failure.
 * @return 2100003: internal error.
 * @permission ohos.permission.INTERNET
 * @syscap SystemCapability.Communication.NetManager.Core
 * @since 11
 * @version 1.0
*/
int32_t OH_NetConn_FreeDnsResult(struct addrinfo *res);

/**
 * @brief Registers a custom DNS resolver.
 *
 * @param resolve Pointer to the custom DNS resolver.
 * @return 0: success.
 * @return 201: insufficient permission.
 * @return 401: parameter error.
 * @return 2100002: service connection failure.
 * @return 2100003: internal error.
 * @permission ohos.permission.INTERNET
 * @syscap SystemCapability.Communication.NetManager.Core
 * @since 11
 * @version 1.0
*/
int32_t OHOS_NetConn_RegisterDnsHook(customdnsresolve resolve);

/**
 * @brief Unregisters a custom DNS resolver.
 *
 * @return 0: success.
 * @return 201: insufficient permission.
 * @return 401: parameter error.
 * @return 2100002: service connection failure.
 * @return 2100003: internal error.
 * @permission ohos.permission.INTERNET
 * @syscap SystemCapability.Communication.NetManager.Core
 * @since 11
 * @version 1.0
*/
int32_t OHOS_NetConn_UnRegisterDnsHook(void);

#ifdef __cplusplus
}
#endif

/** @} */
#endif /* NATIVE_NET_CONN_API_H */
